/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "imageknife_node_animator.h"
#include "imageknife_node_custom.h"
#include "imageknife_internal.h"

namespace ImageKnifePro {

// static 在主线程中执行
std::shared_ptr<ImageKnifeNode> ImageKnifeNode::CreateImageKnifeNode(std::shared_ptr<ImageKnifeOption> option)
{
    IMAGE_KNIFE_CHECK_RETURN(option == nullptr, nullptr);
    auto imageNode = std::make_shared<ImageKnifeNodeImage>(option);
    ImageKnifeInternal::GetInstance().SetImageNode(imageNode);
    return imageNode;
}

// static 在主线程中执行
std::shared_ptr<ImageKnifeNode> ImageKnifeNode::CreateImageKnifeNodeAnimator(std::shared_ptr<ImageKnifeOption> option,
    std::shared_ptr<AnimatorOption> animatorOption)
{
    IMAGE_KNIFE_CHECK_RETURN(option == nullptr, nullptr);
    auto imageNode = std::make_shared<ImageKnifeNodeAnimator>(option, animatorOption);
    ImageKnifeInternal::GetInstance().SetImageNode(imageNode);
    return imageNode;
}

// static 在主线程中执行
std::shared_ptr<ImageKnifeNode> ImageKnifeNode::CreateImageKnifeView(std::string componentId,
                                                                     ArkUI_NodeContentHandle contentSlot,
                                                                     std::shared_ptr<ImageKnifeOption> option,
                                                                     std::shared_ptr<AnimatorOption> animatorOption)
{
    IMAGE_KNIFE_CHECK_RETURN(option == nullptr, nullptr);
    auto imageNode = std::make_shared<ImageKnifeNodeCustom>(option);
    imageNode->UpdateAnimatorOption(animatorOption);
    imageNode->SetComponentId(componentId);

    ImageKnifeInternal::GetInstance().SetRootNode(componentId, contentSlot, imageNode);
    return imageNode;
}

// static 在主线程中执行
std::shared_ptr<ImageKnifeNode> ImageKnifeNode::CreateImageKnifeNode(std::string componentId,
                                                                     ArkUI_NodeContentHandle contentSlot,
                                                                     std::shared_ptr<ImageKnifeOption> option,
                                                                     std::shared_ptr<AnimatorOption> animeOption)
{
    IMAGE_KNIFE_CHECK_RETURN(option == nullptr, nullptr);
    auto imageNode = std::make_shared<ImageKnifeNodeImage>(option);
    imageNode->UpdateAnimatorOption(animeOption);
    imageNode->SetComponentId(componentId);

    ImageKnifeInternal::GetInstance().SetRootNode(componentId, contentSlot, imageNode);
    return imageNode;
}

std::shared_ptr<ImageKnifeNode> ImageKnifeNode::GetImageKnifeNode(std::string componentId)
{
    return ImageKnifeInternal::GetInstance().GetImageNode(componentId);
}
};